import java.util.*;

/**
 * @author: zh
 * @date: 2021/12/17 23:49
 * @version: 1.0
 */
public class Zh0202System extends Zh0202Mediator {
    private Hashtable enterprises = new Hashtable();
    private ArrayList<Zh0202Enterprise> meetingList = new ArrayList<>();
    @Override
    public void addEnterprise(Zh0202Enterprise enterprise) {
        if (!enterprises.contains(enterprise)){
            enterprises.put(enterprise.getName(),enterprise);
            enterprise.setMediator(this);
        }
        meetingList.add(enterprise);
    }

    @Override
    public void sendMsg(String from, String to, String msg) {
        Zh0202Enterprise enterprise = (Zh0202Enterprise) enterprises.get(to);
        enterprise.receiveMsg(from,msg);
    }

    public void sendNotice(String msg){
        System.out.println("发送    "+msg+"    的通知给所有注册用户");
        for (Zh0202Enterprise enterprise : meetingList) {
            enterprise.reponse();
        }
    }
}
